
	<style type="text/css">
		#fm<?=$objectId;?>{
			margin:0;
			padding:10px 30px;
		}
		
	</style>
	<div class="easyui-panel" title="Kriteria Pencarian" style="width:auto;height:150px;padding:10px;"
				data-options="iconCls:'icon-search',collapsible:true,collapsed:true">
		<table border="0" cellpadding="1" cellspacing="1" width="100%">
            <tr>
                <td>
              
                    <table border="0" cellpadding="1" cellspacing="4">				
                    <tr>
                        <td>Periode : &nbsp;</td>
                        <td><input name="periodeawal" id="periodeawal<?=$objectId;?>" class="easyui-datebox" style="width:100px" data-options="formatter:myDateFormatter,parser:myDateParser"  > s.d. <input style="width:100px" name="periodeakhir" id="periodeakhir<?=$objectId;?>" class="easyui-datebox" data-options="formatter:myDateFormatter,parser:myDateParser"  ></td>
                        <td width="20px">&nbsp;</td>
                        <td>Bidang : &nbsp;</td>
                        <td> <?=$bidanglistFilter?>  </td>
                        
                    </tr>
					
					 <tr>
                        <td>No.Urut : &nbsp;</td>
                        <td><input type="text" size="33px" name="txtNomor" style="padding:7px;font-size:14px" id="txtNomor<?=$objectId;?>" class="easyui-validatebox"/></td> 
						<td width="20px">&nbsp;</td>
						<td>No.Tanda Terima : &nbsp;</td>
                        <td><input type="text" size="33px" name="txtNomorTerima" style="padding:7px;font-size:14px" id="txtNomorTerima<?=$objectId;?>" class="easyui-validatebox"/></td>
					</tr>	
                   
                    <tr>
                        <td align="right" colspan="5" valign="top">
                                <a href="#" class="easyui-linkbutton" onclick="clearFilter<?=$objectId;?>();" iconCls="icon-reset">Reset</a>
                                <a href="#" class="easyui-linkbutton" onclick="searchData<?=$objectId;?>();" iconCls="icon-search">Cari</a>
                        </td>
                    </tr>
                    </table>
              
                </td>
            </tr>
            </table>
	</div>			
	<div id="tb<?=$objectId;?>" style="height:auto">
	  <div style="margin-bottom:5px">
		<? if($this->sys_menu_model->cekAkses('ADD;',22,$this->session->userdata('group_id'),$this->session->userdata('level_id'))){?>
			<a href="#" onclick="newData<?=$objectId;?>();" class="easyui-linkbutton" iconCls="icon-add" plain="true">Terima</a>  
		<?}?>
		<? if($this->sys_menu_model->cekAkses('VIEW;',22,$this->session->userdata('group_id'),$this->session->userdata('level_id'))){?>
			 <a href="#" onclick="editData<?=$objectId;?>();" class="easyui-linkbutton" iconCls="icon-view" plain="true">Lihat</a>  
		<?}?>
		<? if($this->sys_menu_model->cekAkses('DELETE;',22,$this->session->userdata('group_id'),$this->session->userdata('level_id'))){?>
			<!-- <a href="#" onclick="deleteData<=$objectId;?>();" class="easyui-linkbutton" iconCls="icon-remove" plain="true">Hapus</a> -->
		<?}?>
		<? if($this->sys_menu_model->cekAkses('PRINT;',22,$this->session->userdata('group_id'),$this->session->userdata('level_id'))){?>
			<a href="#" onclick="printData<?=$objectId;?>();" class="easyui-linkbutton" iconCls="icon-print" plain="true">Print</a>
		<?}?>
		<? if($this->sys_menu_model->cekAkses('EXCEL;',22,$this->session->userdata('group_id'),$this->session->userdata('level_id'))){?>
			<a href="#" onclick="toExcel<?=$objectId;?>();" class="easyui-linkbutton" iconCls="icon-excel" plain="true">Excel</a>
		<?}?>
	  </div>
	</div>
	
	<table id="dg<?=$objectId;?>"  iconCls='icon-save' style="height:auto;width:auto" title="Data Tanda Terima " toolbar="#tb<?=$objectId;?>" 
               fitColumns="true" singleSelect="true" rownumbers="true" pagination="true" noWrap="false" showFooter="true">
	  <thead>
	  <tr>
	    <th colspan="3" halign="center">Tanda Terima</th>
		<th colspan="7" halign="center">Data Pertanggungjawaban</th>
	  </tr>
	  <tr>
		<th halign="center" align="left" field="tanggal" sortable="true" width="90">Tanggal</th>
		<th halign="center" align="center" field="nomor" sortable="true" width="200">No.Tanda Terima</th>
		<th halign="center" align="left" field="penyerah" sortable="true" width="200">Yang Menyerahkan</th>
		<th halign="center" align="left" rowspan="2" field="tgl_spb" sortable="true" width="90">Tanggal</th>
		<th halign="center" align="center" rowspan="2" field="nomor_spb" sortable="true" width="200">No.Urut</th>
		<th halign="center" align="right" rowspan="2" field="jumlah" sortable="true" width="100" formatter="formatMoney">Jumlah</th>
		<th halign="center" align="left" rowspan="2" field="bidang" sortable="true" width="150">Bidang</th>
		<th halign="center" align="left" rowspan="2" field="kategori" sortable="true" width="100">Kategori</th>
		<th halign="center" align="left" rowspan="2" field="untuk" sortable="true" width="200">Untuk Pembayaran</th>
		<th halign="center" align="left" rowspan="2" field="tujuan" sortable="true" width="100">Kepada</th>
		<th halign="center"  align="center" field="beban_kode" hidden="true">Kode</th>
		<th halign="center" align="left" field="beban_kegiatan" hidden="true">Kegiatan</th>		
		<th halign="center" field="tanda_id"  rowspan="2"  hidden="true"  width="20">tanda_id</th>
		<th halign="center" field="spb_id" hidden="true"  width="0">spb_id</th>
	  </tr>
         
	  </thead> 
	</table>


	 <!-- AREA untuk Form Add/EDIT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  -->
	
	<div id="dlg<?=$objectId;?>" class="easyui-dialog" style="width:800px;height:600px;padding:10px 20px" closed="true" buttons="#dlg-buttons<?=$objectId;?>">
	  <div class="ftitle">Tanda Terima Dokumen Pengajuan</div>
	  <form id="fm<?=$objectId;?>" method="post">
	    <div class="fitem">
            <label style="width:150px;vertical-align:top">Tanggal :</label>
            <input name="tanggal" style="width:100px" id="tanggal<?=$objectId;?>" class="easyui-datebox" value="<?=date('d-m-Y')?>" data-options="formatter:myDateFormatter,parser:myDateParser,disabled:true,onSelect:onSelect<?=$objectId?>"  required="true"><span><i>Otomatis</i></<span>
          </div>
        <div class="fitem">
            <label style="width:150px;vertical-align:top">No.Tanda Terima :</label>
            <input name="nomor" id="nomor<?=$objectId?>" class="easyui-validatebox" readonly="readonly"  style="text-transform: uppercase" required="true" size="30">
          </div>
        <div class="fitem" style="display:none">
            <label style="width:150px;vertical-align:top">Bidang :</label>
           <?='';//$bidanglist?>  
          </div>

          <div class="fitem">
            <label style="width:150px;vertical-align:top" >Keterangan :</label>
            <textarea name="keterangan"  id="keterangan<?=$objectId?>" cols="50"></textarea>
            <input name="spb_ids" id="spb_ids<?=$objectId?>" type="hidden" > 
            <input name="tanda_id" id="tanda_id<?=$objectId?>" type="hidden" > 
            <input name="spb_id" id="spb_id<?=$objectId?>" type="hidden" > 
          </div>
		  <div class="fitem">
            <label style="width:150px;vertical-align:top" >Yang Menyerahkan :</label>
             <input  name="penyerah"  id="penyerah<?=$objectId?>" size="50" />
             
          </div>
		  
		  <fieldset>
			<legend>&nbsp;&nbsp;Data Permohonan</legend>
		 <div class="fitem">
		  <label style="width:150px;">Tanggal :</label>
		  <input name="tgl_spb" style="width:100px" id="tgl_spb<?=$objectId;?>" class="easyui-validatebox" readonly="readonly"   required="true">
		</div>
         <div class="fitem">
		  <label style="width:150px;vertical-align:top">No.Urut :</label>
                 <input name="nomor_spb" id="nomor_spb<?=$objectId?>" class="easyui-validatebox"  readonly="readonly" style="text-transform: uppercase" required="true" >
					&nbsp;
                  <input type="checkbox" style="display:none" name="revisi" id="chkRevisi<?=$objectId?>" value="1"  />&nbsp;<!--Revisi-->
				  
		</div>
        <div class="fitem">
		  <label style="width:150px;vertical-align:top">Bidang :</label>
		  <input name="bidang" id="bidang<?=$objectId?>"  class="easyui-validatebox" size="50" readonly="readonly">
		</div>
              <div class="fitem">
		  <label style="width:150px;vertical-align:top">Kategori :</label>
		  <input name="kategori" id="kategori<?=$objectId?>"  class="easyui-validatebox" size="30" readonly="readonly">
		</div>
		<div class="fitem">
		  <label style="width:150px;">Dibayarkan kepada :</label>
		  <input name="tujuan" id="tujuan<?=$objectId?>"  class="easyui-validatebox" size="30" readonly="readonly">
		</div>
		<div class="fitem">
		  <label style="width:150px;vertical-align:top">Tujuan Pembayaran :</label>
		  <textarea name="untuk" id="untuk<?=$objectId?>" class="easyui-validatebox" cols="90"  readonly="readonly"></textarea>
		</div>
		<div class="fitem">
		  <label style="width:150px;vertical-align:top">Beban Kegiatan :</label>
                 <input name="beban_kode" class="easyui-validatebox" size="30" required="true" readonly="readonly"> 
				    
                
		</div>
               <div class="fitem">
		  <label style="width:150px;vertical-align:top">Nama Beban Kegiatan :</label>
		  <input name="beban_kegiatan" class="easyui-validatebox" size="70" required="true" readonly="readonly">
		</div> 
              <div class="fitem">
		  <label style="width:150px;vertical-align:top">Jumlah :</label>
		  <input name="jumlah" id="jumlah<?=$objectId?>" class="easyui-numberbox" style="text-align:right" readonly="readonly" data-options="precision:0,groupSeparator:'.',decimalSeparator:','"  >
		</div>
		</fieldset>
	  </form>
    </div>
    <div id="dlg-buttons<?=$objectId;?>">
	  <a id="btn-cetakulang<?=$objectId?>" href="#" class="easyui-linkbutton hide" iconCls="icon-ok" onclick="printTandaTerima<?=$objectId;?>()">Cetak Ulang</a>
	  <a id="btn-simpan<?=$objectId?>" href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveData<?=$objectId;?>()">Simpan</a>
	  <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg<?=$objectId;?>').dialog('close')">Batal</a>
    </div>

<script  type="text/javascript" >
$(function(){
    var url;
    var idTanda<?=$objectId;?>;
    var rowIndexDetail;
       

    newData<?=$objectId;?> = function (){    
		var row = $('#dg<?=$objectId;?>').datagrid('getSelected');
		if (row){
			//addTab("Tambah Tanda Terima","transaksi/tandaterima/add/"+row.spb_id);
		//	alert(row.tanda_id);
			if (row.tanda_id!=null){
				alert('Dokumen ini sudah pernah diterima');return;
			}
			
			$('#btn-simpan<?=$objectId;?>').show();  
			$('#btn-cetakulang<?=$objectId;?>').hide();  
			$('#dlg<?=$objectId;?>').dialog('open').dialog('setTitle','Tanda Terima Dokumen Pengajuan');  
			$('#fm<?=$objectId;?>').form('clear');  
			 $('#fm<?=$objectId;?>').form('load',row);
			$('#tanda_id<?=$objectId;?>').val(row.tanda_id);  
			$('#tanggal<?=$objectId;?>').datebox('setValue','<?=date('d-m-Y')?>');
			var editmode = ($('#tanda_id<?=$objectId;?>').val()!="");
            setNewNumber<?=$objectId?>(editmode);
			url=base_url+'transaksi/tandaterima/save/'+(editmode?"edit/"+$('#tanda_id<?=$objectId?>').val():"add");
		  //  $('#nomor<?=$objectId;?>').val('/PPK/<?=date('Y')?>');  
			//setNewNumber<?=$objectId?>();
		}else{
			alert('Pilih data permohonan terlebih dahulu');
		}
    }
    //end newData 
	  onSelect<?=$objectId?> = function(){
			var editmode = ($('#tanda_id<?=$objectId;?>').val()!="");
            setNewNumber<?=$objectId?>(editmode);
        }
		
		function setNewNumber<?=$objectId?>(editmode){
            if (!editmode){
				$("#nomor<?=$objectId?>").val('OTOMATIS');
				return;//nomor pada saat save saja
				var tanggal =  $('#tanggal<?=$objectId;?>').datebox('getValue');
				var arrTgl  = tanggal.split("-");
				$.ajax({url:base_url+"transaksi/tandaterima/get_new_number/"+arrTgl[1]+"/"+arrTgl[2],
					success : function(data){
					$("#nomor<?=$objectId?>").val(data);
					}					
				})
            }
        }
        
    clearFilter<?=$objectId;?> = function (){
        //ambil nilai-nilai filter
            $("#filter_bidang_id<?=$objectId?>").val('-1');
            $("#filter_kategori_id<?=$objectId?>").val('-1');
            $('#periodeawal<?=$objectId;?>').datebox('setValue','<?=date('01-m-Y')?>');
            $('#periodeakhir<?=$objectId;?>').datebox('setValue','<?=date('d-m-Y')?>');
			$("#txtNomor<?=$objectId?>").val('');
			$("#txtNomorTerima<?=$objectId?>").val('');
//        $("#filter_alamat").val('');


        //$('#dg<=$objectId;?>').datagrid({url:"<=base_url()?>transaksi/tandaterima/grid/"+filnip+"/"+filnama+"/"+filalamat});
    }

        //tipe 1=grid, 2=pdf, 3=excel
    getUrl<?=$objectId;?> = function (tipe){
        var filawal =  $('#periodeawal<?=$objectId;?>').datebox('getValue');	
        var filakhir = $("#periodeakhir<?=$objectId;?>").datebox('getValue');	
        var filbidang = $("#filter_bidang_id<?=$objectId;?>").combobox('getValue');
		var filnomor = $("#txtNomor<?=$objectId;?>").val();
		var filnomorTerima = $("#txtNomorTerima<?=$objectId;?>").val();
//        var filkategori = $("#filter_kategori_id<?=$objectId;?>").val();
        

        filbidang = ((filbidang=="undefined")||(filbidang=="")||(filbidang==null))?"-1":filbidang;
        filnomor = ((filnomor=="undefined")||(filnomor=="")||(filnomor==null))?"-1":filnomor;
        filnomorTerima = ((filnomorTerima=="undefined")||(filnomorTerima=="")||(filnomorTerima==null))?"-1":filnomorTerima;
  //      filkategori = ((filkategori=="undefined")||(filkategori=="")||(filbidang==null))?"-1":filkategori;
        if (tipe==1){
                return "<?=base_url()?>transaksi/tandaterima/grid/<?=$tipetandaterima?>/"+filawal+"/"+filakhir+"/"+filbidang+"/"+filnomor+"/"+filnomorTerima;
        }
        else if (tipe==2){
                return "<?=base_url()?>transaksi/tandaterima/pdf/<?=$tipetandaterima?>/"+filawal+"/"+filakhir+"/"+filbidang+"/"+filnomor+"/"+filnomorTerima;
        }else if (tipe==3){
                return "<?=base_url()?>transaksi/tandaterima/excel/<?=$tipetandaterima?>/"+filawal+"/"+filakhir+"/"+filbidang+"/"+filnomor+"/"+filnomorTerima;
        }

    }

	searchData<?=$objectId;?> = function (){
        //ambil nilai-nilai filter
        $('#dg<?=$objectId;?>').datagrid({
            url:getUrl<?=$objectId;?>(1)
            
             
         
        });
    }
	
    searchDataOld<?=$objectId;?> = function (){
        //ambil nilai-nilai filter
        $('#dg<?=$objectId;?>').datagrid({
            url:getUrl<?=$objectId;?>(1),
            view: detailview,
            detailFormatter:function(index,row){
               return '<div style="padding:2px"><table id="ddv<?=$objectId;?>-' + index + '"></table></div>';
           //  return "tes";
           },
           onExpandRow: function(index,row){
                           //	alert(row.id_pk_e1);

               $('#ddv<?=$objectId;?>-'+index).datagrid({
                   url:'<?=base_url()?>transaksi/tandaterima/griddetail/'+row.tanda_id+'/?parentIndex='+index,
                   fitColumns:true,
                   singleSelect:true,
                   rownumbers:true,
                   loadMsg:'',
                   height:'auto',
                   columns:[[
                       {field:'detail_id',title:'detail_id',hidden:true},
                       {field:'tanda_id',title:'tanda_id',hidden:true},
                       {field:'spb_id',title:'spb_id',hidden:true},
                       {field:'tanggal',title:'Tanggal',width:80},
                       {field:'nomor',title:'Nomor SPB',width:200},
                       {field:'jumlah',title:'Jumlah',width:100,align:'right'},
                       {field:'kategori',title:'Kategori',width:100},
                       {field:'untuk',title:'Untuk Pembayaran',width:200}
                       
                   ]],
                   onResize:function(){
                       $('#dg<?=$objectId;?>').datagrid('fixDetailRowHeight',index);
                   },
                  onClickCell:function(rowIndex, field, value){
                        $('#ddv<?=$objectId;?>-'+index).datagrid('selectRow', rowIndex);
                       var row = $('#ddv<?=$objectId;?>-'+index).datagrid('getSelected');
                       idTanda<?=$objectId;?> = row.tanda_id;
                       rowIndexDetail = index;
                                                   //alert(idTanda);
                    },
                   onLoadSuccess:function(){
                       setTimeout(function(){
                           $('#dg<?=$objectId;?>').datagrid('fixDetailRowHeight',index);
                       },0);
                   }
               });
               $('#dg<?=$objectId;?>').datagrid('fixDetailRowHeight',index);


           }
        });
    }
    //end searhData 

    editData<?=$objectId;?> = function (){
        var row = $('#dg<?=$objectId;?>').datagrid('getSelected');
        if (row){
			//addTab("Tambah Tanda Terima","transaksi/tandaterima/add/"+row.spb_id);
		//	alert(row.tanda_id);
			if (row.tanda_id==null){
				alert('Dokumen ini belum pernah diterima');return;
			}
			$('#btn-simpan<?=$objectId;?>').hide();  
			$('#btn-cetakulang<?=$objectId;?>').show();  
			$('#dlg<?=$objectId;?>').dialog('open').dialog('setTitle','Tanda Terima Dokumen Pengajuan');  
			$('#fm<?=$objectId;?>').form('clear');  
			 $('#fm<?=$objectId;?>').form('load',row);
			$('#tanda_id<?=$objectId;?>').val(row.tanda_id);  
			$('#tanggal<?=$objectId;?>').datebox('setValue','<?=date('d-m-Y')?>');
			var editmode = ($('#tanda_id<?=$objectId;?>').val()!="");
           setNewNumber<?=$objectId?>(editmode);
			url=base_url+'transaksi/tandaterima/save/'+(editmode?"edit/"+$('#tanda_id<?=$objectId?>').val():"add");
		  //  $('#nomor<?=$objectId;?>').val('/PPK/<?=date('Y')?>');  
			//setNewNumber<?=$objectId?>();
		}else{
			alert('Pilih data permohonan terlebih dahulu');
		}
        //alert(row.dokter_kode);
      //  if (row){
           //     $('#dlg<?=$objectId;?>').dialog('open').dialog('setTitle','Edit Tanda Terima SPBY');
             //   $('#fm<?=$objectId;?>').form('load',row);
             // addTab("Edit Tanda Terima","transaksi/tandaterima/edit/"+row.tanda_id); 
            // url = base_url+'transaksi/tandaterima/save/edit/'+row.tanda_id;//+row.id;//'update_user.php?id='+row.id;
       // }
    }
        //end editData
	
	printTandaTerima<?=$objectId;?> = function(){
		//printData<?=$objectId;?>($('#tanda_id<?=$objectId;?>').val());
		window.open(base_url+"transaksi/tandaterima/print_tandaterima/"+$('#tanda_id<?=$objectId;?>').val());;
	}
	 
	 
	saveData<?=$objectId;?>=function(){
		//alert(url);return;
        $('#fm<?=$objectId;?>').form('submit',{
            url: url,
            onSubmit: function(){
               
                // var ids = [];
                // var rows = $("#dg<?=$objectId?>").datagrid('getSelections');
                // for(var i=0; i<rows.length; i++){
                    // ids.push(rows[i].spb_id);
                // }
                
                // $("#spb_ids<?=$objectId?>").val(ids.join(','));
                
                return $(this).form('validate');
            },
            success: function(result){
               // alert(result);
                var result = eval('('+result+')');
                if (result.success){
                    $.messager.show({
                            title: 'Pesan',
                            msg: 'Data berhasil disimpan'
                    });
					if (confirm("Cetak Tanda Terima ?")){
						// printData<?=$objectId;?>(result.tandaid);
						window.open(base_url+"transaksi/tandaterima/print_tandaterima/"+result.tandaid);;
					}
                   $('#dlg<?=$objectId;?>').dialog('close');		// close the dialog
					//$('#tt').tabs('close', '<=($editmode?"Edit":"Tambah")?> Tanda Terima');
                   $('#dg<?=$objectId;?>').datagrid('reload');	// reload the user data
                } else {
                    $.messager.show({
                            title: 'Error',
                            msg: result.msg
                    });
                }
            }
        });
    }

	// printData<?=$objectId;?>=function(tandaid){			
     	// if ((tandaid=="") ||(tandaid=="0"))
			// alert("Tanda terima belum disimpan");
		// else
			// window.open(base_url+"transaksi/tandaterima/print_tandaterima/"+tandaid);;
	 
    // }
		
    deleteData<?=$objectId;?> = function (){
        var row = $('#dg<?=$objectId;?>').datagrid('getSelected');
        if(row){
            if(confirm("Apakah yakin akan menghapus data Tanda Terima dengan nomor '" + row.nomor + "'?")){
                var response = '';
                $.ajax({ type: "GET",
                    url: base_url+'transaksi/tandaterima/delete/' + row.tanda_id ,
                    async: false,
                    success : function(response){
                        var response = eval('('+response+')');
                        if (response.success){
                            $.messager.show({
                                title: 'Success',
                                msg: 'Data Berhasil Dihapus'
                            });

                            // reload and close tab
                            $('#dg<?=$objectId;?>').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: response.msg
                            });
                        }
                    }
                });
            }
        }
    }
        //end deleteData 

    printData<?=$objectId;?>=function(){			
        //$.jqURL.loc(getUrl<?=$objectId;?>(2),{w:800,h:600,wintype:"_blank"});
		//alert("underconstruction");return;
        window.open(getUrl<?=$objectId;?>(2));;
    }

    toExcel<?=$objectId;?>=function(){
		//alert("underconstruction");return;
        window.open(getUrl<?=$objectId;?>(3));;
    }

   
        

        setTimeout(function(){
            var wHeight = $(window).height();
            clearFilter<?=$objectId?>();
            $("#dg<?=$objectId;?>").css('height',wHeight-183);    
            searchData<?=$objectId?>();
                
        },100);
 });
</script>	